<template>
	<view class="container">
		<!-- 内容流 -->
		<scroll-view scroll-y class="content-stream">
			<view class="post-grid">
				<view v-for="(post, index) in posts" :key="index" class="post" @tap="navigateToDetail(post)">
					<view class="author-info">
						<image :src="post.author.avatar" class="avatar"></image>
						<text class="nickname">{{ post.author.nickname }}</text>
						<text class="time">{{ post.time }}</text>
					</view>
					<text class="caption">{{ post.caption }}</text>
					<image :src="post.image" class="post-image" mode="widthFix"></image>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
export default {
  data() {
    return {
      posts: [
        {
          id: 1,
          author: {
            avatar: 'http://localhost:8080/1.jpg',
            nickname: '用户A',
          },
          time: '1小时前',
          caption: '今天去了新开业的咖啡馆，好喝又好看！',
          content: 'hhhhhhhhhhh好一个传统的京酱肉丝卷饼自己用饺子皮做的春卷皮方便又好吃不知道吃什么的时候就试试这个吧~✨小红书即将发 ',
          image: 'http://localhost:8080/1.jpg',
        },
        {
          id: 2,
          author: {
            avatar: 'http://localhost:8080/1.jpg',
            nickname: '用户B',
          },
          time: '2小时前',
          caption: '周末去郊游啦～',
          content: '太棒了hhhhhhhhhhh好',
          image: 'http://localhost:8080/2.png',
        },
        {
          id: 3,
          author: {
            avatar: 'http://localhost:8080/1.jpg',
            nickname: '用户C',
          },
          time: '3小时前',
          caption: '新买的裙子真漂亮！',
          content: '宝宝宝宝宝宝hhhhhhhhhhh好',
          image: 'http://localhost:8080/1.jpg',
        },
        {
          id: 4,
          author: {
            avatar: 'http://localhost:8080/1.jpg',
            nickname: '用户D',
          },
          time: '4小时前',
          caption: '夜跑感受不同哦～',
          content: '阿斯顿飞过归还借款hhhhhhhhhhh好',
          image: 'http://localhost:8080/1.jpg',
        },
      ],
    };
  },
  methods: {
    navigateToDetail(post) {
      // 将对象转换为JSON字符串，然后进行编码
      const params = encodeURIComponent(JSON.stringify(post));
      uni.navigateTo({
        url: `/pages/strategy/contentDetail?params=${params}`,
      });
    },
  },
};
</script>

<style>
	.container {
		display: flex;
		flex-direction: column;
		height: 100vh;
	}

	.content-stream {
		flex: 1;
	}

	.post-grid {
		display: grid;
		/* grid-template-columns: repeat(2, 1fr); */
		grid-auto-rows: auto;
	}

	.post {
		background-color: #fff;
		border-radius: 10px;
		box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
		padding: 10px;
		margin: 8px;
		transition: transform 0.2s ease-in-out;
		cursor: pointer;
		display: inline-block;
		/* 添加鼠标指针样式 */
	}

	.post:hover {
		transform: translateY(-5px);
	}

	.author-info {
		display: flex;
		align-items: center;
	}

	.avatar {
		width: 30px;
		height: 30px;
		border-radius: 50%;
		margin-right: 10px;
	}

	.nickname {
		font-size: 16px;
		font-weight: bold;
		margin-right: 10px;
	}

	.time {
		color: #999;
		font-size: 12px;
	}

	.caption {
		margin-top: 10px;
		font-size: 14px;

		/* 限制文本 */
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		max-width: 100%;
	}

	.post-image {
		margin-top: 10px;
		width: 100%;
		border-radius: 10px;
	}
</style>